﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using WebShopData;

namespace WebShop_Project
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {
            List<ShoppingCartItem> shoppingCartItems = new List<ShoppingCartItem>();
            //shoppingCartItems.Add(new ShoppingCartItem(Articles.GetArticle(1)));
            //shoppingCartItems.Add(new ShoppingCartItem(Articles.GetArticle(2)));
            //shoppingCartItems.Add(new ShoppingCartItem(Articles.GetArticle(3)));
            Session.Add("ShoppingCart", shoppingCartItems);
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            if(Server.GetLastError().InnerException != null)
            {
                string message = Server.GetLastError().InnerException.Message.ToString();
                string type = Server.GetLastError().GetType().ToString();
                DBException.AddException(message, type);
            }
            else
            {
                string message = Server.GetLastError().Message.ToString();
                string type = Server.GetLastError().GetType().ToString();
                DBException.AddException(message, type);
            }     
            Response.Redirect("http://localhost:26945/ErrorPage.aspx");
        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}